package com.ywd.materials.admin.controller;

import com.ywd.materials.admin.common.Common;
import com.ywd.materials.admin.dto.MaterialsWarehouseDto;
import com.ywd.materials.admin.dto.query.MaterialsWarehouseQuery;
import com.ywd.materials.admin.dto.query.MaterialsWarehouseOneQuery;
import com.ywd.materials.admin.exception.R;
import com.ywd.materials.admin.exception.RPage;
import com.ywd.materials.admin.service.impl.MaterialsWarehouseServiceImpl;
import com.ywd.materials.admin.vo.MaterialsWarehousePartVo;
import com.ywd.materials.admin.vo.MaterialsWarehouseTreeVo;
import com.ywd.materials.admin.vo.MaterialsWarehouseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lk
 * @date 2024/4/17 13:53
 */
@AllArgsConstructor
@RestController
@RequestMapping("/warehouse")
@Tag(name = "仓库管理")
public class MaterialsWarehouseController {

    private final MaterialsWarehouseServiceImpl materialsWarehouseServiceImpl;

    @PostMapping("/getWarehouseTree")
    @Operation(summary = "仓库列表(树形)")
    public R<List<MaterialsWarehouseTreeVo>> getWarehouseTree(@RequestBody MaterialsWarehouseOneQuery query) {
        return R.ok(materialsWarehouseServiceImpl.getWarehouseTree(query));
    }

    @PostMapping("/getWarehousePage")
    @Operation(summary = "仓库列表(分页)")
    public R<RPage<List<MaterialsWarehouseVo>>> getWarehousePage(@RequestBody MaterialsWarehouseQuery query) {
        return R.ok(materialsWarehouseServiceImpl.getWarehousePage(query));
    }

    @GetMapping("/getNextWarehouseList")
    @Operation(summary = "查询下级仓库列表")
    public R<List<MaterialsWarehousePartVo>> getNextWarehouseList(@Schema(description = "仓库ID") @RequestParam Long id) {
        return R.ok(materialsWarehouseServiceImpl.getNextWarehouseList(id));
    }

    @GetMapping("/getWarehouseDetails")
    @Operation(summary = "仓库详情",hidden = true)
    public R<MaterialsWarehouseVo> getWarehouseDetails(@Schema(description = "仓库ID") @RequestParam Long id) {
        return R.ok(materialsWarehouseServiceImpl.getWarehouseDetails(id));
    }

    @PostMapping("/saveWarehouse")
    @Operation(summary = "新增仓库")
    public R<Boolean> saveWarehouse(@RequestBody MaterialsWarehouseDto dto) {
        return R.ok(materialsWarehouseServiceImpl.saveWarehouse(dto));
    }

    @PutMapping("/updateWarehouse")
    @Operation(summary = "修改仓库")
    public R<Boolean> updateWarehouse(@RequestBody MaterialsWarehouseDto dto) {
        return R.ok(materialsWarehouseServiceImpl.updateWarehouse(dto));
    }

    @DeleteMapping("/deleteWarehouse")
    @Operation(summary = "删除仓库")
    public R<Boolean> deleteWarehouse(@Schema(description = "仓库ID") @RequestParam Long id) {
        return R.ok(materialsWarehouseServiceImpl.deleteWarehouse(id));
    }


    @GetMapping("/getWarehouseListCommon")
    @Operation(summary = "仓库列表(筛选项)")
    public R<List<Common>> getWarehouseListCommon(@Schema(description = "名称") @RequestParam(required = false) String name) {
        return R.ok(materialsWarehouseServiceImpl.getWarehouseListCommon(name));
    }


}
